<?php

require_once 'dbconfig.php';

$i = 0;
$coords = "";
$output = array();


	
	$query = <<<END
		SELECT *
		FROM  pickups2; 
END;

	$result = mysql_query ( $query, $connection );
	$size = mysql_num_rows($result); 

	$i = 0;
	while ( $row = mysql_fetch_array ( $result ) ) {
		$id = $row[0];
		$name = $row[1]." ".$row[2];
		$phone_number = "(".$row[3].")".$row[4]."-".$row[5];
		$address_line_one = $row[6];
		$address_line_two = $row[8].", ".$row[9];
		$email = $row[10];
		$times = $row[11];
		$tree_info = $row[12];
		$add_info = $row[14];
		$status = $row[15];
		$lat = $row[16];
		$lng = $row[17];
		$category =$row[18];
		
		$statustext = "";
		if ($status == "complete") {
                break;
        }
        if ($status == "open") {
                $statustext = <<<END
                    <input id="saveForm" type="submit" onclick="reserve_pickup($id)" value="Reserve Pickup" />
END;
        } else {
                $statustext = "Reserved";
        }
        
        		$infobox = <<<END
		<div id = "contact$i">
			<div>$name</div>
			<div>$address_line_one</div>
			<div>$address_line_two</div>
			<div>$phone_number</div>
			<div>$email</div>
			<p>Times Available: $times</p>
			<p>Food Available: $tree_info</p>
			<p>Additional Information: $add_info</p>
		</div>
END;
		
		$info = array('id' => $id, 'name' => $name, 'phone' => $phone_number ,'address1' => $address_line_one,
		 		'address2' => $address_line_two , 'email' => $email, 'times' => $times , 'treeInfo' => $tree_info,
		  		'addInfo' => $add_info,  'status' => $status, 'lat' => $lat, 'lng' => $lng, 'category' => $category , 
				'infobox' => $infobox);
		
		array_push($output, $info);
		
		$i++;
	}
	echo json_encode($output);
//}

?>